﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TimeProject.Engine;

namespace TimeProject.WebSite.Views
{
    public static class ViewDataExtensions
    {
        private const string UserInfoKey = "userInfo";

        public static void SetUserInfo(this ViewDataDictionary viewData, UserInfo user)
        {
            if (viewData == null)
            {
                throw new ArgumentNullException("viewData");
            }

            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            viewData[UserInfoKey] = user;
        }

        public static UserInfo GetUserInfo(this ViewDataDictionary viewData)
        {
            if (viewData == null)
            {
                throw new ArgumentNullException("viewData");
            }

            UserInfo user = null;
            if (viewData.ContainsKey(UserInfoKey))
            {
                user = viewData[UserInfoKey] as UserInfo;
            }
            return user;
        }

    }
}